//登陆注册共用js
$(function() {

	console.log("这位看源代码童鞋，雷好啊！")

	// 看不清楚换一张
	$("#changeImgLoginBtn").click(function() {
		$("#img").attr("src", "../../../getImgVerify.action?" + Math.random());
	})
	// 校验图片验证码
	$("#imgCode").blur(function() {
		var imageVal = $('#imgCode').val();// 获取输入的验证码的值
		if (imageVal != null && imageVal != "") {
			$.ajax({
				type : 'post',
				url : '/tenement/checkImgVerify.action',
				data : imageVal,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					console.log("msg:" + msg);
					if (msg) {
						$("#imgCodeTip").css("display", "none");
						$("#imgCodeFlag").attr("value", "true");
					} else {
						$("#imgCodeTip").css("display", "block");
						$("#imgCodeFlag").attr("value", "false");
					}
				}
			})
		}
	})

	// 校验输入的手机验证码
/*	$("#sms").blur(function() {
		var code = $('#sms').val();// 获取输入的验证码的值
		if (code != null && code != "") {
			$.ajax({
				type : 'post',
				url : '/tenement/verifyPhoneCode.action',
				data : code,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					console.log("msg:" + msg);
					if (msg=="1") {
						$("#phoneCodeTip").css("display", "none");
						$("#smsFlag").attr("value", "true");
					} else {
						$("#phoneCodeTip").css("display", "block");
						$("#smsFlag").attr("value", "false");
					}
				}
			})
		}
	})*/

	// 邮箱数据校验
	var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;// 邮箱正则表达式
	// 邮箱格式校验
	$("#emailIpt").bind("input propertychange change", function(event) {
		var email_val = $("#emailIpt").val(); // 获取邮箱输入框的值
		// 校验
		if (!emailReg.test(email_val)) {
		} else {
		}

	})
	// 判断邮箱是否已被注册
	$("#emailIpt").blur(function() {

		if (emailFlag == true) {
			var email = $("#emailIpt").val();
			console.log("【输入邮箱的值】" + email)
			$.ajax({
				type : 'post',
				url : '/tenement/verifyEmailUsed.action',
				data : email,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					if (msg == 1) {
						$("#emailImgTip").attr("src", "images/base/false.png");
						$("#emailTip").css("display", "block");
						$("#emailTip").html("该邮箱已经被注册");// 改变提示信息
					} else {
						$("#emailTip").css("display", "none");
					}
				}
			})
		}

	});
	// 发送验证码
	var emailVerifyCode = "";// 邮箱验证码
	$("#getEmailSecurityCodeBtn").click(function() {

		if (emailFlag == true) {
			var emailaddress = $("#emailIpt").val();
			console.log("【输入邮箱的值】" + emailaddress)
			$.ajax({
				type : 'post',
				url : '/tenement/getEmailVerifyCode.action',
				data : emailaddress,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					console.log("【后台发送的验证码】" + msg)
					if (msg != "") {
						emailVerifyCode = msg;
					} else {

					}
				}
			})
		}
	});

})
